﻿using System.Collections.Generic;
using UnityEngine;
using VoxelBlock.VoxelBlock3D;
using VoxelBlock;using Vector3Int = VoxelBlock.Vector3Int;

public class OperationImplementBrushRemove : OperationImplement
{

    //public OperationImplementBrushRemove(ProxyOperation proxy) : base(proxy)
    //{

    //}

    public override void Start(StartArg arg)
    {
        //this.nowDrawVoxel3DCore = arg.nowDrawVoxel3DCore;
        base.Start(arg);

    }

    public override void Run(RunArg arg)
    {
         var arrayPoint = BasicAlgorithm.GetLineBlock3D(arg.updateStartPosition, arg.nowSelectPosition);
        //添加历史记录
        historyRecordFrontList.AddRange(nowDrawVoxel3DCore.DrawRemoveBlock(arrayPoint));
    }

    public override void Over(OverArg arg)
    {
        if (isStop)
        {
            if (historyRecordFrontList.Count > 0)
            {
                proxy.Write(VoxelCategories.Operation.Remove, historyRecordFrontList, historyRecordBreakList);
                //historyRecordBreakList = new List<SimpleVoxel>();
                historyRecordFrontList = new List<SimpleVoxel>();
            }
        }
        else
        {
            if (historyRecordFrontList.Count > 0)
            {
                proxy.Write(VoxelCategories.Operation.Remove, historyRecordFrontList, historyRecordBreakList);
                //historyRecordBreakList = new List<SimpleVoxel>();
                historyRecordFrontList = new List<SimpleVoxel>();
            }
            else
            {
                historyRecordFrontList = nowDrawVoxel3DCore.DrawRemoveBlock(new Vector3Int[] { arg.nowSelectPosition });
                if (historyRecordFrontList.Count > 0)
                {
                    proxy.Write(VoxelCategories.Operation.Remove, historyRecordFrontList, historyRecordBreakList);
                    historyRecordFrontList = new List<SimpleVoxel>();
                }
            }
        }
    }

}


